package com.probiz.estore.imports.handler.order;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.probiz.estore.common.model.order.OrderShipment;
import com.probiz.estore.imports.handler.ColumnHandler;
import com.probiz.estore.imports.handler.basic.ColumnBasicHandler;
import com.probiz.estore.imports.model.Column;
import com.probiz.estore.imports.model.ImportModel;
import com.probiz.estore.order.service.OrderShipmentManager;
import com.probiz.estore.order.service.SalesOrderManager;

public class ShippingNoHandler extends ColumnBasicHandler implements ColumnHandler{
	private Logger logger = Logger.getLogger(ShippingNoHandler.class);
	private SalesOrderManager salesOrderManager;
	private OrderShipmentManager orderShipmentManager;
	public void setSalesOrderManager(SalesOrderManager salesOrderManager) {
		this.salesOrderManager = salesOrderManager;
	}
	public void setOrderShipmentManager(OrderShipmentManager orderShipmentManager) {
		this.orderShipmentManager = orderShipmentManager;
	}
	
	public void setProperty(ImportModel importModel, Column column)
			throws Exception {
		OrderShipment orderShipment=(OrderShipment)importModel.getTarget();
		String value = column.getValue();
		if(StringUtils.isNotEmpty(value)){
			OrderShipment orderShipment2=this.orderShipmentManager.getByDocumentNo(value);
			if(orderShipment2!=null){
				orderShipment=orderShipment2;
				importModel.setTarget(orderShipment);
				importModel.setUpdate(true);
				importModel.setResult(ImportModel.RESULT_SUCCESS); 
			}else{//新增不操作
				String msg = "没有找到指定相应的发货单("+value+")";
				logger.error(msg);
				importModel.setMsg(msg);
				importModel.setResult(ImportModel.RESULT_ERROR); 
				
			}
			
		}else{
			String msg = "没有指定相应的发货单";
			logger.error(msg);
			importModel.setMsg(msg);
			importModel.setResult(ImportModel.RESULT_ERROR);
		}
	}
	
	

}
